package flc.ast.adapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

import java.text.SimpleDateFormat;

import flc.ast.R;
import flc.ast.bean.OvertimeRecordBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;

public class OvertimeRecordAdapter extends StkProviderMultiAdapter<OvertimeRecordBean> {


    public OvertimeRecordAdapter() {
        addItemProvider(new OvertimeRecordProvider());
    }

    private class OvertimeRecordProvider extends BaseItemProvider<OvertimeRecordBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_overtime_record;
        }

        @Override
        public void convert(@NotNull BaseViewHolder baseViewHolder, OvertimeRecordBean bean) {
            String today = TimeUtils.getNowString(new SimpleDateFormat("MM-dd EEEE"));
            if (bean.getTime().equals(today)) {
                baseViewHolder.setText(R.id.tvOvertimeRecordItemDate, bean.getTime() + getContext().getString(R.string.today_tip));
            } else {
                baseViewHolder.setText(R.id.tvOvertimeRecordItemDate, bean.getTime());
            }

            RecyclerView rvChild = baseViewHolder.getView(R.id.rvChildList);
            rvChild.setLayoutManager(new LinearLayoutManager(getContext()));
            OvertimeChildAdapter albumChildAdapter = new OvertimeChildAdapter();
            rvChild.setAdapter(albumChildAdapter);
            albumChildAdapter.setList(bean.getOvertimeBeanList());
            albumChildAdapter.setOnItemClickListener(getOnItemClickListener());
        }
    }
}
